#!/bin/bash
set -eu
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
AVATAR_NODE="$(command -v node || true)"
if [ -z "$AVATAR_NODE" ]; then
  for candidate in "$HOME"/.nvm/versions/node/*/bin/node; do
    if [ -x "$candidate" ]; then AVATAR_NODE="$candidate"; fi
  done
fi
if [ -z "$AVATAR_NODE" ]; then
  /usr/bin/osascript -e 'display alert "Creator Studio" message "Necesitas Node.js 22 o superior. Instala Node.js LTS desde nodejs.org y vuelve a abrir el estudio."'
  exit 1
fi
AVATAR_CONTENTS="$(cd "$(dirname "$0")/.." && pwd)"
exec "$AVATAR_NODE" "$AVATAR_CONTENTS/Resources/studio/src/launch.mjs"
